package org.dromara.system.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.WbCompanyProductListVo;
import org.dromara.system.domain.bo.WbCompanyProductListBo;
import org.dromara.system.service.IWbCompanyProductListService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 各公司产品信息
 *
 * @author Lion Li
 * @date 2024-04-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/companyProductList")
public class WbCompanyProductListController extends BaseController {

    private final IWbCompanyProductListService wbCompanyProductListService;

    /**
     * 查询各公司产品信息列表
     */
    @SaCheckPermission("system:companyProductList:list")
    @GetMapping("/list")
    public TableDataInfo<WbCompanyProductListVo> list(WbCompanyProductListBo bo, PageQuery pageQuery) {
        return wbCompanyProductListService.queryPageList(bo, pageQuery);
    }
    /**
     * 查询各公司产品信息列表
     * 带公司经营产品
     */
    @SaCheckPermission("system:companyProductList:list")
    @GetMapping("/listZ")
    public TableDataInfo<WbCompanyProductListVo> listZ(WbCompanyProductListBo bo, PageQuery pageQuery) {
        return wbCompanyProductListService.queryPageListZ(bo, pageQuery);
    }




    /**
     * 导出各公司产品信息列表
     */
    @SaCheckPermission("system:companyProductList:export")
    @Log(title = "各公司产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WbCompanyProductListBo bo, HttpServletResponse response) {
        List<WbCompanyProductListVo> list = wbCompanyProductListService.queryList(bo);
        ExcelUtil.exportExcel(list, "各公司产品信息", WbCompanyProductListVo.class, response);
    }

    /**
     * 获取各公司产品信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:companyProductList:query")
    @GetMapping("/{id}")
    public R<WbCompanyProductListVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(wbCompanyProductListService.queryById(id));
    }

    /**
     * 新增各公司产品信息
     */
    @SaCheckPermission("system:companyProductList:add")
    @Log(title = "各公司产品信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WbCompanyProductListBo bo) {
        return toAjax(wbCompanyProductListService.insertByBo(bo));
    }

    /**
     * 修改各公司产品信息
     */
    @SaCheckPermission("system:companyProductList:edit")
    @Log(title = "各公司产品信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WbCompanyProductListBo bo) {
        return toAjax(wbCompanyProductListService.updateByBo(bo));
    }

    /**
     * 删除各公司产品信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:companyProductList:remove")
    @Log(title = "各公司产品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(wbCompanyProductListService.deleteWithValidByIds(List.of(ids), true));
    }

    @GetMapping("/listSift")
    public TableDataInfo listSift(WbCompanyProductListBo bo, PageQuery pageQuery) {
        return wbCompanyProductListService.queryListSift(bo, pageQuery);
    }
}
